package com.atguigu.gmall.order.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQDelayQueueConfiguration {

    @Bean
    public Exchange orderExchange() {
        Exchange exchange = ExchangeBuilder.directExchange("order.exchange").durable(true).build();
        return exchange ;
    }

    @Bean
    public Queue orderQueue() {
        Queue queue = QueueBuilder.durable("order_queue")
                .ttl(1000 * 60 * 30)
                .deadLetterExchange("order.exchange")
                .deadLetterRoutingKey("close.order")
                .build();
        return queue ;
    }

    @Bean
    public Binding orderQueueBinding() {
        Binding binding = BindingBuilder.bind(orderQueue()).to(orderExchange()).with("order.info").noargs();
        return binding ;
    }

    @Bean
    public Queue closeOrderQueue() {
        Queue closeOrderQueue = QueueBuilder.durable("close_order_queue")
                .build();
        return closeOrderQueue ;
    }

    @Bean
    public Binding closeOrderQueueBinding() {
        Binding binding = BindingBuilder.bind(closeOrderQueue()).to(orderExchange()).with("close.order").noargs();
        return binding ;
    }

}
